package com.bie.action;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.util.ServletContextAware;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.woke.bean.CjPrizeBean;
import com.woke.bean.UserBean;
import com.woke.dao.CjPrize;
import com.woke.dao.User;

public class CjPrizeAction implements Action, ServletRequestAware, ServletResponseAware, ServletContextAware {
	private HttpServletRequest request;
	private HttpServletResponse responese;
	private ServletContext application;
	private String id;
	private String prizename;
	private String password;
	private String sex;
	private String tel;
	private String email;
	private String role;
	private String message;
	private String createtime;
	private String updatetime;
	private User u;
	private String probability;
	private String cjid;
	private String rank;
	

	public String getProbability() {
		return probability;
	}

	public void setProbability(String probability) {
		this.probability = probability;
	}

	public String getCjid() {
		return cjid;
	}

	public void setCjid(String cjid) {
		this.cjid = cjid;
	}

	public String getRank() {
		return rank;
	}

	public void setRank(String rank) {
		this.rank = rank;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getCreatetime() {
		return createtime;
	}

	public void setCreatetime(String createtime) {
		this.createtime = createtime;
	}

	public String getUpdatetime() {
		return updatetime;
	}

	public void setUpdatetime(String updatetime) {
		this.updatetime = updatetime;
	}

	public String getRole() {
		return role;
	}

	public void setRole(String role) {
		this.role = role;
	}


	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	
	public String getPrizename() {
		return prizename;
	}

	public void setPrizename(String prizename) {
		this.prizename = prizename;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public User getUser() {
		return u;
	}

	public void setUser(User u) {
		this.u = u;
	}

	public String execute() throws Exception {

		return null;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;

	}

	public void setServletResponse(HttpServletResponse response) {
		this.responese = response;

	}

	public void setServletContext(ServletContext application) {
		this.application = application;

	}

	public String getCjPrizeList() throws Exception {
		List<CjPrize> list = new ArrayList<CjPrize>();
		CjPrizeBean bm = new CjPrizeBean();
		list = bm.getCjPrizeList();
		ActionContext.getContext().put("Cjprizelist", list);
		return "ceshicj";
	}
	
	public String deleprize() throws Exception {
		CjPrizeBean bm = new CjPrizeBean();
		System.out.println("删除编号："+id);
		bm.deletecjprize(id);
		return "prizelist";
	}

	public String addPrize() throws Exception {
		CjPrizeBean bm = new CjPrizeBean();
		prizename= new String(prizename.getBytes("ISO-8859-1"),"utf-8");
		bm.addcjprize(cjid, prizename, probability, rank);
			return "prizelist";
	}

	public String updateprize() throws Exception {
		CjPrizeBean bm = new CjPrizeBean();
		String s = String.valueOf(id);
		System.out.println("probability:"+probability);
		prizename= new String(prizename.getBytes("ISO-8859-1"),"utf-8");
		bm.updatecjprize(s, cjid, prizename, probability, rank);
		return "prizelist";
	}
	
	public String updatepwd() throws Exception {
		UserBean bm = new UserBean();
		String s = String.valueOf(id);
		bm.updatepassword(s, password);
		return getCjPrizeList();
	}

	public String updateRole() throws Exception {
		UserBean bm = new UserBean();
		String s = String.valueOf(id);
		role= new String(role.getBytes("ISO-8859-1"),"utf-8");
		System.out.println("修改权限："+role+"编号："+id);
		if(role.equals("超级管理员")) {
			bm.updaterole(s, "管理员");
		}else {
			bm.updaterole(s, "超级管理员");
		}
		
		return "adminrole";
	}
	
	

}
